//
//  FormatFontExample.m
//  libxlsxwriter-ObjC
//
//  Created by Ludovico Rossi on 11/11/15.
//  Copyright © 2015 Ludovico Rossi. All rights reserved.
//

#import <libxlsxwriter/xlsxwriter.h>
#import "FormatFontExample.h"

@implementation FormatFontExample

- (NSString *)title {
    return @"Format Font";
}

- (NSString *)subtitle {
    return @"Example of writing data with font formatting";
}

- (NSString *)outputFileName {
    return @"format_font";
}

- (void)run {
    /*
     * Example of writing some data with font formatting to a simple Excel
     * file using libxlsxwriter.
     *
     * Copyright 2014-2015, John McNamara, jmcnamara@cpan.org
     *
     */
    
    /* Create a new workbook. */
    lxw_workbook  *workbook  = new_workbook([self.outputFilePath fileSystemRepresentation]);
    
    /* Add a worksheet. */
    lxw_worksheet *worksheet = workbook_add_worksheet(workbook, NULL);
    
    /* Widen the first column to make the text clearer. */
    worksheet_set_column(worksheet, 0, 0, 20, NULL);
    
    /* Add some formats. */
    lxw_format    *format1   = workbook_add_format(workbook);
    lxw_format    *format2   = workbook_add_format(workbook);
    lxw_format    *format3   = workbook_add_format(workbook);
    
    /* Set the bold property for format 1. */
    format_set_bold(format1);
    
    /* Set the italic property for format 2. */
    format_set_italic(format2);
    
    /* Set the bold and italic properties for format 3. */
    format_set_bold  (format3);
    format_set_italic(format3);
    
    /* Write some formatted strings. */
    worksheet_write_string(worksheet, 0, 0, "This is bold",    format1);
    worksheet_write_string(worksheet, 1, 0, "This is italic",  format2);
    worksheet_write_string(worksheet, 2, 0, "Bold and italic", format3);
    
    /* Close the workbook, save the file and free any memory. */
    workbook_close(workbook);
}

@end
